package cn.tedu.fx;

/**
 * 泛型方法是写在方法上声明的<T>，泛型类是写在类上面的<T>
 */
public class 泛型方法泛型类 {
    public static void main(String[] args) {
        Teacher instance1 = instance(Teacher.class);
        System.out.println(instance1);
    }

    public  <T>T  instance(Object o,Class<T> cls){
        return (T)o;
    }

    /**
     * 反射new对象
     * @param cls
     * @return
     * @param <T>
     */
    public static  <T>T  instance(Class<T>cls){
        try {
            return cls.newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
